<?php

namespace App\Http\Requests\Api;


use Illuminate\Support\Facades\Redis;

class GoodsSeckillRequest extends FormRequest
{

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'goods_id'=> [
                'required',
                function($attribute,$value,$fail){
                    $sku = Redis::get("seckill_sku_".$value);
//                    dd($sku);
                    if (is_null($sku)){
                        return $fail("商品不存在");
                    }
                    if ($sku<1){
                        return $fail("商品已售完");
                    }
                }
            ]
        ];
    }
}
